<template>
	<view class="content">
		<uni-nav-bar color="#FFFFFF" backgroundColor="#0f85ff" class="uni-nav-bar" title="登录"></uni-nav-bar>
		<view class="uni-body">
			<image class="logo" src="../../static/logo.png" mode="widthFix"></image>
			<view class="input-item">
				<input v-model="username" placeholder="账号" type="text" value="" />
			</view>
			<view class="input-item">
				<input v-model="pwd" placeholder="密码" type="text" :password="true" value="" />
			</view>
			<button @tap="login" class="loginbtn" type="primary">登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: '',
				pwd: ''
			}
		},
		onShow () {
			//#ifdef H5
			window.login = this
			//#endif
		},
		methods: {
			async login () {
				var data = {
					username: this.username,
					pwd: this.pwd,
					adminLogin: false,
					mobileLogin: false
				}
				try {
					var result = await this.$fn.postLofin(data)
					if (result.status !== 1) {
						throw new Error('登录失败，请重试！')
						return
					}
					// 登录成功
					var csuser = {
						cs_id: result.user_info.id,
						key: result.key,
						pwd: this.pwd,	
						info: result.user_info
					}
					uni.setStorageSync('csuser', csuser)
					uni.redirectTo({url: '/pages/index/index'})
					console.log(csuser)
				} catch (e) {
					console.log(e.message)
				}
			}
		}
	}
</script>

<style>
	@import './style.css';
</style>
